/**
 * Created by wqz806687102 on 2016/1/11.
 */
'use strict';

angular.module('Query').controller('SingleProductController', ['$scope', 'PublicModule', 'PublicEnum', 'PublicFunction', '$location', 'Authentication',
    function($scope, PublicModule, PublicEnum, PublicFunction, $location, Authentication) {
        $scope.serachText; //关键字
        PublicModule.initModule($scope, 'BarcodeMaster');
        $scope.Module.BarcodeMaster.LoadMode = PublicEnum.LoadMode.CacheAndNoPaging;
        $scope.Module.BarcodeMaster.PageSize = 15;
        $scope.Module.BarcodeMaster.Populate = [{
            path: 'QCReworkOperation',
            select: 'Work'
        }, {
            path: 'Users',
            select: 'Code Name'
        }];

        PublicModule.initModule($scope, '_BarcodeMaster');
        $scope.Module._BarcodeMaster.LoadMode = PublicEnum.LoadMode.CacheAndNoPaging;
        $scope.Module._BarcodeMaster.PageSize = 15;

        $scope.btnQuery = function() {
            if ($scope.serachText == undefined || $scope.serachText.trim() == '') {
                return;
            };
            //查询条件--条码，作业，批次，物料
            var condition = {};
            condition['Barcode'] = "/" + $scope.serachText + "/";
            condition['WorkName'] = "/" + $scope.serachText + "/";
            condition['MOLotNumber'] = "/" + $scope.serachText + "/";
            condition['ItemMasterName'] = "/" + $scope.serachText + "/";
            this.Module.BarcodeMaster.find(condition, null, null, function(rcds) {
                for (var item in rcds) {
                    for (var user in rcds[item].Users) {
                        if (user == 0) {
                            rcds[item]["username"] = rcds[item].Users[user].Name;
                        } else {
                            rcds[item]["username"] += ',' + rcds[item].Users[user].Name;
                        };
                    };
                };

                $scope.Module._BarcodeMaster.Records = rcds;
                $scope.Module._BarcodeMaster.emitOnLoadEvent();
            });
        };
    }
]);